package top.mybatisx.mpquery.toolkit;

import top.mybatisx.sql.core.toolkit.ChkUtil;

/**
 * 字符串转换工具类
 */
public class StringCaseUtil {

    // 将驼峰转为大写,下划线连接
    public static String camelToUpperCase(String camelCase) {
        if (ChkUtil.isNull(camelCase)) {
            return camelCase;
        }
        camelCase = camelCase.replaceAll("(.)(\\p{Upper})", "$1_$2").toUpperCase();
        return camelCase.replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2")
                .replaceAll("([a-z\\d])([A-Z])", "$1_$2");
    }

    // 将驼峰转为小写字母和下划线连接
    public static String camelToLowercase(String camelCase) {
        return camelCase.replaceAll("(.)(\\p{Upper})", "$1_$2").toLowerCase();
    }


}
